home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / FromTheMag / JW FLV MEDIA PLAYER 4.2 / mediaplayer.exe / player.swf / scripts / com / jeroenwijering / utils / Configger.as < prev    next >
Text File  |  2008-11-04  |  2KB  |  86 lines

  1. package com.jeroenwijering.utils
  2. {
  3.    import flash.display.Sprite;
  4.    import flash.events.Event;
  5.    import flash.events.EventDispatcher;
  6.    import flash.net.URLLoader;
  7.    import flash.net.URLRequest;
  8.    
  9.    public class Configger extends EventDispatcher
  10.    {
  11.        
  12.       
  13.       private var config:Object;
  14.       
  15.       private var reference:Sprite;
  16.       
  17.       private var loader:URLLoader;
  18.       
  19.       public function Configger(param1:Sprite)
  20.       {
  21.          super();
  22.          reference = param1;
  23.       }
  24.       
  25.       private function compareWrite(param1:Object) : void
  26.       {
  27.          var _loc2_:* = null;
  28.          for(_loc2_ in param1)
  29.          {
  30.             config[_loc2_.toLowerCase()] = Strings.serialize(param1[_loc2_.toLowerCase()]);
  31.          }
  32.       }
  33.       
  34.       private function loadXML(param1:String) : void
  35.       {
  36.          var url:String = param1;
  37.          loader = new URLLoader();
  38.          loader.addEventListener(Event.COMPLETE,xmlHandler);
  39.          try
  40.          {
  41.             loader.load(new URLRequest(url));
  42.          }
  43.          catch(err:Error)
  44.          {
  45.             throw err;
  46.          }
  47.       }
  48.       
  49.       private function loadFlashvars() : void
  50.       {
  51.          compareWrite(reference.root.loaderInfo.parameters);
  52.          dispatchEvent(new Event(Event.COMPLETE));
  53.       }
  54.       
  55.       public function load(param1:Object) : void
  56.       {
  57.          var _loc2_:String = null;
  58.          config = param1;
  59.          _loc2_ = reference.root.loaderInfo.parameters["config"];
  60.          if(_loc2_)
  61.          {
  62.             loadXML(Strings.decode(_loc2_));
  63.          }
  64.          else
  65.          {
  66.             loadFlashvars();
  67.          }
  68.       }
  69.       
  70.       private function xmlHandler(param1:Event) : void
  71.       {
  72.          var _loc2_:XML = null;
  73.          var _loc3_:Object = null;
  74.          var _loc4_:XML = null;
  75.          _loc2_ = XML(param1.currentTarget.data);
  76.          _loc3_ = new Object();
  77.          for each(_loc4_ in _loc2_.children())
  78.          {
  79.             _loc3_[_loc4_.name()] = _loc4_.text();
  80.          }
  81.          compareWrite(_loc3_);
  82.          loadFlashvars();
  83.       }
  84.    }
  85. }
  86.